package com.ys.service.finance.impl;

import java.math.BigDecimal;
import java.math.RoundingMode;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ys.config.MyConfig;
import com.ys.constant.AppConstant;
import com.ys.entity.finance.TcwPartnerBankInfo;
import com.ys.entity.finance.TcwPaymentReturnItem;
import com.ys.entity.finance.TcwWanliCnyPaymentItem;
import com.ys.entity.finance.TcwWanliDrawing;
import com.ys.entity.finance.TcwWanliDrawingItem;
import com.ys.entity.finance.TcwWanliOtherPayment;
import com.ys.entity.finance.TcwWanliOtherPaymentItem;
import com.ys.entity.finance.TcwWanliPaymentReturn;
import com.ys.entity.finance.TcwWanliPaymentReturnItem;
import com.ys.entity.finance.TcwWanliPayout;
import com.ys.entity.hr.ThrOperateCompanyBankInfo;
import com.ys.entity.sys.TbCompanyBankInfo;
import com.ys.entity.sys.TbStaticConfig;
import com.ys.enume.finance.PaymentEnum;
import com.ys.enume.finance.TcwBusinessSceneCodeEnum;
import com.ys.enume.finance.TcwExchangeRateEnum;
import com.ys.enume.finance.TcwPaymentMethodTypeEnum;
import com.ys.enume.finance.TcwWanliCnyPaymentEnum;
import com.ys.enume.finance.TcwWanliPayoutEnum;
import com.ys.enume.wanli.WfSubUserEnum;
import com.ys.mapper.finance.TcwWanliDrawingItemMapper;
import com.ys.mapper.finance.TcwWanliPaymentReturnItemMapper;
import com.ys.mapper.finance.TcwWanliPayoutMapper;
import com.ys.service.finance.TcwWanliCnyPaymentService;
import com.ys.service.finance.TcwWanliDrawingService;
import com.ys.service.finance.TcwWanliPaymentReturnService;
import com.ys.service.finance.TcwWanliPayoutService;
import com.ys.util.RandomUtil;
import com.ys.util.wanli.WanliUtils;
import com.ys.vo.R;

@Service("tcwWanliPayoutService")
public class TcwWanliPayoutServiceImpl implements TcwWanliPayoutService {
	
	@Autowired
	private TcwWanliPayoutMapper tcwWanliPayoutMapper;
	@Autowired
	private TcwWanliCnyPaymentService tcwWanliCnyPaymentService;
	@Autowired
	private TcwWanliDrawingItemMapper tcwWanliDrawingItemMapper;
	@Autowired
	private TcwWanliDrawingService tcwWanliDrawingService;
	@Autowired
	private TcwWanliPaymentReturnItemMapper tcwWanliPaymentReturnItemMapper;
	@Autowired
	private TcwWanliPaymentReturnService tcwWanliPaymentReturnService;
	/**
	 * 新增CNY付款单的付款
	 */
	@Override
	public void addPayOfCnyPayment(Long wanliCnyPaymentItemId) throws Exception {
		
		TcwWanliCnyPaymentItem tcwWanliCnyPaymentItem = new TcwWanliCnyPaymentItem().setId(wanliCnyPaymentItemId).queryFirst();
		if (tcwWanliCnyPaymentItem.getStatePay() == PaymentEnum.StatePay.SUCCESS.value) {
			return;
		}
		
		TcwPartnerBankInfo tcwPartnerBankInfo = new TcwPartnerBankInfo().setVid(tcwWanliCnyPaymentItem.getPartnerBankInfoVid()).queryFirst();
		
		// 万里汇clientId配置
		TbStaticConfig tbStaticConfig = new TbStaticConfig().setKeyTwo("wanli-mid-clientId").queryFirst();
		
		JSONObject resultJOConsult = null;
		{	
	        String content = "";
	        JSONObject jsonObject = new JSONObject();
	
	        JSONObject transferFromDetail = new JSONObject();
	        JSONObject transferFromAmount = new JSONObject();
	        transferFromAmount.put("currency", tcwWanliCnyPaymentItem.getCurrencyCodeOut()); // 汇出币种
	        transferFromAmount.put("value", tcwWanliCnyPaymentItem.getAmountOut().multiply(new BigDecimal(100)));
	        transferFromDetail.put("transferFromAmount",transferFromAmount);
	        jsonObject.put("transferFromDetail",transferFromDetail);
	
	        JSONObject transferToDetail = new JSONObject();
	        JSONObject transferToMethod = new JSONObject();
	
	        transferToMethod.put("paymentMethodType","BANK_ACCOUNT_DETAIL");
	
	        JSONObject paymentMethodMetaData = new JSONObject();
	
	        paymentMethodMetaData.put("bankAccountLocalName", tcwPartnerBankInfo.getVyhzhmc()); // 银行账户名称，如：莫程集团控股有限公司
	        paymentMethodMetaData.put("bankLocalName", tcwPartnerBankInfo.getVkhh()); // 开户行名称，如：中国工商银行福州金山支行
	        paymentMethodMetaData.put("bankAccountNo", tcwPartnerBankInfo.getVyhzh()); // 银行账号，如：1402267709600003989
	        
	        paymentMethodMetaData.put("beneficiaryType", "THIRD_PARTY_COMPANY_BANK_ACCOUNT"); // 受益人类型：THIRD_PARTY_PERSONAL_BANK_ACCOUNT和THIRD_PARTY_COMPANY_BANK_ACCOUNT
	        paymentMethodMetaData.put("bankCountryCode", "CN"); // 受益人国家编码，固定两字符
	        //beneficiaryType=THIRD_PARTY_COMPANY_BANK_ACCOUNT(企业银行卡) 该routingNumber（银行支行联行号）字段必填
	        paymentMethodMetaData.put("routingNumber", tcwPartnerBankInfo.getVlhh()); // 联行号，如：301394000013
	        // 需要注意每个国家的简称提前设置
	        transferToMethod.put("paymentMethodMetaData", paymentMethodMetaData);
	
	        transferToDetail.put("transferToMethod", transferToMethod);
	
	        JSONObject transferToAmount = new JSONObject();
	        transferToAmount.put("currency", "CNY");
	
	        transferToDetail.put("transferToAmount", transferToAmount);
	        jsonObject.put("transferToDetail", transferToDetail);
	        jsonObject.put("businessSceneCode", "THIRD_PARTY_PAYOUT");
	        content = JSONObject.toJSONString(jsonObject);
	
	        String httpMethod = "POST";
	        String clientId = tbStaticConfig.getName();
	        String uriWithQueryString = "/amsin/api/v1/business/fund/consultPayout";
	        String connectedCustomerId = "";
	        String result = WanliUtils.result(content, httpMethod, uriWithQueryString, clientId,connectedCustomerId);
	        System.out.println("consultPayoutresult=" + result);
	        
	        resultJOConsult = JSON.parseObject(result);
	        boolean flag = false;
	        if (resultJOConsult.containsKey("result")) {
				JSONObject resultJO = resultJOConsult.getJSONObject("result");
				if (resultJO.containsKey("resultCode") && resultJO.getString("resultCode").equals("SUCCESS")) {
					flag = true;
				}
			}
	        if (flag == false) {
				return;
			}
		}

		/*
		 * 
		 */
        JSONObject paymentMethodMetaDataJO = new JSONObject();
        paymentMethodMetaDataJO.put("bankAccountLocalName", tcwPartnerBankInfo.getVyhzhmc()); // 银行账户名称，如：莫程集团控股有限公司
        paymentMethodMetaDataJO.put("bankLocalName", tcwPartnerBankInfo.getVkhh()); // 开户行名称，如：中国工商银行福州金山支行
        paymentMethodMetaDataJO.put("bankAccountNo", tcwPartnerBankInfo.getVyhzh()); // 银行账号，如：1402267709600003989
        paymentMethodMetaDataJO.put("beneficiaryType", "THIRD_PARTY_PERSONAL_BANK_ACCOUNT"); // 受益人类型：THIRD_PARTY_PERSONAL_BANK_ACCOUNT和THIRD_PARTY_COMPANY_BANK_ACCOUNT
        paymentMethodMetaDataJO.put("bankCountryCode", "CN"); // 受益人国家编码，固定两字符
        //beneficiaryType=THIRD_PARTY_COMPANY_BANK_ACCOUNT(企业银行卡) 该routingNumber（银行支行联行号）字段必填
        paymentMethodMetaDataJO.put("routingNumber", tcwPartnerBankInfo.getVlhh()); // 联行号，如：301394000013

        /*
         * 获取汇率
         */
        JSONObject transferToDetailJO = JSONObject.parseObject(resultJOConsult.get("transferToDetail").toString());
        JSONObject transferQuoteJO = new JSONObject();
        if (transferToDetailJO.containsKey("transferQuote")){
            JSONObject transferQuoteJo = transferToDetailJO.getJSONObject("transferQuote");
            transferQuoteJO.put("quoteId", transferQuoteJo.get("quoteId"));
        }
		
		// 添加万里汇订单记录
		TcwWanliPayout tcwWanliPayout = null;
		{
			String mid = null;
			Integer type = TcwWanliPayoutEnum.Type.TCW_WANLICNYPAYMENT.value;
			Long relativeId = wanliCnyPaymentItemId;
			String transferRequestId = RandomUtil.getGUID();
			String orderNo = null;
			BigDecimal transferFromAmountValue = tcwWanliCnyPaymentItem.getAmountOut().multiply(new BigDecimal(100));
			String currencyCode = tcwWanliCnyPaymentItem.getCurrencyCodeOut();
			String paymentMethodType = "BANK_ACCOUNT_DETAIL";
			String paymentMethodId = resultJOConsult
					.getJSONObject("transferToDetail")
					.getJSONObject("transferToMethod")
					.getString("paymentMethodId");
			String paymentMethodMetaData = paymentMethodMetaDataJO.toJSONString();
			BigDecimal transferToAmountValue = tcwWanliCnyPaymentItem.getAmountIn();
			String transferQuote = transferQuoteJO.toJSONString();
			String transferNotifyUrl = MyConfig.getUrlDomain() + "/api/outer/wfStore/test4";
			String transferRemark = null;
			String transferMemo = null;
			String extendInfo = null;
			String purposeCode = "GDS";
			String arrivalType = null;
			String businessSceneCode = "THIRD_PARTY_PAYOUT";
			BigDecimal feeAmount = transferToDetailJO.getJSONObject("feeAmount").getBigDecimal("value");
			String resultCode = null;
			String resultMessage = null;
			String resultStatus = null;
			Integer state = TcwWanliPayoutEnum.State.INIT.value;
			tcwWanliPayout = TcwWanliPayout.tcwWanliPayout(mid, type, relativeId, transferRequestId, orderNo,
					transferFromAmountValue, currencyCode, paymentMethodType, paymentMethodId, paymentMethodMetaData,
					transferToAmountValue, transferQuote, transferNotifyUrl, transferRemark, transferMemo,
					extendInfo, purposeCode, arrivalType, businessSceneCode, feeAmount,
					resultCode, resultMessage, resultStatus, state, 1);
			tcwWanliPayoutMapper.insert(tcwWanliPayout);
		}
		
		{
	        String content = "";
	        JSONObject jsonObject = new JSONObject();
	        jsonObject.put("transferRequestId", tcwWanliPayout.getTransferRequestId());

	        JSONObject transferFromDetail = new JSONObject();
	        JSONObject transferFromAmount = new JSONObject();
	        transferFromAmount.put("currency", tcwWanliCnyPaymentItem.getCurrencyCodeOut());
	        transferFromAmount.put("value", tcwWanliCnyPaymentItem.getAmountOut().multiply(new BigDecimal(100)));
	        transferFromDetail.put("transferFromAmount", transferFromAmount);
	        jsonObject.put("transferFromDetail", transferFromDetail);

	        JSONObject transferToDetail = new JSONObject();
	        JSONObject transferToMethod = new JSONObject();

	        transferToMethod.put("paymentMethodType", "BANK_ACCOUNT_DETAIL");

	        transferToMethod.put("paymentMethodMetaData", paymentMethodMetaDataJO);

	        transferToDetail.put("transferToMethod", transferToMethod);

	        JSONObject transferToAmount = new JSONObject();
	        transferToAmount.put("currency", "CNY");

	        transferToDetail.put("transferToAmount", transferToAmount);

	        transferToDetail.put("purposeCode", "GDS"); // 转账目的代码
	        //用于接收转账通知的地址，万里汇会使用此地址将转账结果通过notifyTransfer接口发送给集成商。
	        transferToDetail.put("transferNotifyUrl", MyConfig.getUrlDomain() + "/api/outer/wfStore/test4");

            transferToDetail.put("transferQuote", transferQuoteJO);

	        jsonObject.put("transferToDetail",transferToDetail);
	        
	        /*
	         * 转账业务类型码
	         * THIRD_PARTY_PAYOUT：转账到第三方卡。第三方卡包括企业卡和个人卡
	         * SAME_NAME_PAYOUT：提现到同名卡。
	         */
	        jsonObject.put("businessSceneCode", "THIRD_PARTY_PAYOUT");

	        content = JSONObject.toJSONString(jsonObject);

	        String httpMethod = "POST";
	        String clientId = tbStaticConfig.getName();
	        String uriWithQueryString = "/amsin/api/v1/business/fund/createPayout";
	        String connectedCustomerId = "";
	        /*
	         * {"businessSceneCode":"THIRD_PARTY_PAYOUT","result":{"resultCode":"PROCESSING","resultMessage":"request is processing.","resultStatus":"S"},"transferFromDetail":{"transferFromAmount":{"currency":"EUR","value":5000},"transferFromMethod":{"customerId":"2120220018087007","paymentMethodType":"BALANCE"}},"transferId":"2024061819121000110000001073757","transferOrderAddition":{},"transferRequestId":"ecc18279-3c51-4bb4-8b9d-526a203433a9","transferToDetail":{"feeAmount":{"currency":"EUR","value":15},"purposeCode":"GDS","transferNotifyUrl":"http://localhost:9999/api/outer/wfStore/test6","transferQuote":{"quoteCurrencyPair":"EUR/CNY","quoteExpiryTime":"2024-06-18T08:39:32Z","quoteId":"20230929C50030530001336311","quotePrice":"7.70174920","quoteStartTime":"2023-09-29T07:42:55Z"},"transferToAmount":{"currency":"CNY","value":38393},"transferToMethod":{"paymentMethodId":"2024061819027700120305109984749","paymentMethodType":"BANK_ACCOUNT_DETAIL"}}}
	         */
	        System.out.println("content===" + content);
	        String result = WanliUtils.result(content, httpMethod, uriWithQueryString, clientId,connectedCustomerId);
	        System.out.println("createPayoutresult===" + result);
		}
	}
	
	/**
	 * 新增CNY付款单的付款
	 */
	@Override
	public void addPayOfOtherPayment(Long wanliOtherPaymentItemId) throws Exception {
		
		TcwWanliOtherPaymentItem tcwWanliOtherPaymentItem = new TcwWanliOtherPaymentItem().setId(wanliOtherPaymentItemId).queryFirst();
		if (tcwWanliOtherPaymentItem.getStatePay() == PaymentEnum.StatePay.SUCCESS.value) {
			return;
		}
		TcwWanliOtherPayment tcwWanliOtherPayment = new TcwWanliOtherPayment().setBid(tcwWanliOtherPaymentItem.getPbid()).queryFirst();
		
		// 万里汇clientId配置
		TbStaticConfig tbStaticConfig = new TbStaticConfig().setKeyTwo("wanli-mid-clientId").queryFirst();
		
		JSONObject resultJOConsult = null;
		{	
	        String content = "";
	        JSONObject jsonObject = new JSONObject();
	
	        JSONObject transferFromDetail = new JSONObject();
	        JSONObject transferFromAmount = new JSONObject();
	        transferFromAmount.put("currency", tcwWanliOtherPayment.getCurrencyCodeOut()); // 汇出币种
	        transferFromAmount.put("value", tcwWanliOtherPaymentItem.getAmount().multiply(new BigDecimal(100)));
	        transferFromDetail.put("transferFromAmount",transferFromAmount);
	        jsonObject.put("transferFromDetail",transferFromDetail);
	
	        JSONObject transferToDetail = new JSONObject();
	        JSONObject transferToMethod = new JSONObject();
	
	        transferToMethod.put("paymentMethodType","BANK_ACCOUNT_DETAIL");
	
	        JSONObject paymentMethodMetaData = new JSONObject();
	
	        /*
	         * 转入货币为USD，参数：
	         * bankAccountName
	         * routingNumber
	         * bankBIC
	         * bankAccountNo
	         */
//	        paymentMethodMetaData.put("bankAccountName","Amazon.com Services LLC");
//	        paymentMethodMetaData.put("routingNumber","121000248");
//	        paymentMethodMetaData.put("bankBIC","WFBIUS6SXXX");
//	        paymentMethodMetaData.put("bankAccountNo","43530001477785130");
//	        paymentMethodMetaData.put("beneficiaryType","THIRD_PARTY_COMPANY_BANK_ACCOUNT");
//	        paymentMethodMetaData.put("bankCountryCode","US");
	        paymentMethodMetaData.put("bankAccountName", tcwWanliOtherPaymentItem.getVyhzhmc()); // 银行账户名称，如：莫程集团控股有限公司
	        paymentMethodMetaData.put("routingNumber", tcwWanliOtherPaymentItem.getVaba()); // 联行号，如：301394000013
	        paymentMethodMetaData.put("bankBIC", tcwWanliOtherPaymentItem.getSwiftCode()); // 开户行名称，如：中国工商银行福州金山支行
	        paymentMethodMetaData.put("bankAccountNo", tcwWanliOtherPaymentItem.getVyhzh()); // 银行账号，如：1402267709600003989
	        paymentMethodMetaData.put("beneficiaryType","THIRD_PARTY_COMPANY_BANK_ACCOUNT");
	        
	        paymentMethodMetaData.put("bankCountryCode", tcwWanliOtherPayment.getCountryCode());
	        
	        //beneficiaryType=THIRD_PARTY_COMPANY_BANK_ACCOUNT(企业银行卡) 该routingNumber（银行支行联行号）字段必填
	        // 需要注意每个国家的简称提前设置
	        transferToMethod.put("paymentMethodMetaData", paymentMethodMetaData);
	
	        transferToDetail.put("transferToMethod", transferToMethod);
	
	        JSONObject transferToAmount = new JSONObject();
	        transferToAmount.put("currency", tcwWanliOtherPayment.getCurrencyCodeOut());
	
	        transferToDetail.put("transferToAmount", transferToAmount);
	        jsonObject.put("transferToDetail", transferToDetail);
	        jsonObject.put("businessSceneCode", "THIRD_PARTY_PAYOUT");
	        content = JSONObject.toJSONString(jsonObject);
	
	        String httpMethod = "POST";
	        String clientId = tbStaticConfig.getName();
	        String uriWithQueryString = "/amsin/api/v1/business/fund/consultPayout";
	        String connectedCustomerId = "";
	        String result = WanliUtils.result(content, httpMethod, uriWithQueryString, clientId,connectedCustomerId);
	        System.out.println("consultPayoutresult=" + result);
	        
	        resultJOConsult = JSON.parseObject(result);
	        boolean flag = false;
	        if (resultJOConsult.containsKey("result")) {
				JSONObject resultJO = resultJOConsult.getJSONObject("result");
				if (resultJO.containsKey("resultCode") && resultJO.getString("resultCode").equals("SUCCESS")) {
					flag = true;
				}
			}
	        if (flag == false) {
				return;
			}
		}

		/*
		 * 
		 */
        JSONObject paymentMethodMetaDataJO = new JSONObject();
        paymentMethodMetaDataJO.put("bankAccountName", tcwWanliOtherPaymentItem.getVyhzhmc()); // 银行账户名称，如：莫程集团控股有限公司
        paymentMethodMetaDataJO.put("routingNumber", tcwWanliOtherPaymentItem.getVaba()); // 联行号，如：301394000013
        paymentMethodMetaDataJO.put("bankBIC", tcwWanliOtherPaymentItem.getSwiftCode()); // 开户行名称，如：中国工商银行福州金山支行
        paymentMethodMetaDataJO.put("bankAccountNo", tcwWanliOtherPaymentItem.getVyhzh()); // 银行账号，如：1402267709600003989
        paymentMethodMetaDataJO.put("beneficiaryType","THIRD_PARTY_COMPANY_BANK_ACCOUNT");
        paymentMethodMetaDataJO.put("bankCountryCode", tcwWanliOtherPayment.getCountryCode());

        /*
         * 获取汇率
         */
        JSONObject transferToDetailJO = JSONObject.parseObject(resultJOConsult.get("transferToDetail").toString());
        JSONObject transferQuoteJO = new JSONObject();
        if (transferToDetailJO.containsKey("transferQuote")){
            JSONObject transferQuoteJo = transferToDetailJO.getJSONObject("transferQuote");
            transferQuoteJO.put("quoteId", transferQuoteJo.get("quoteId"));
        }
		
		// 添加万里汇订单记录
		TcwWanliPayout tcwWanliPayout = null;
		{
			String mid = null;
			Integer type = TcwWanliPayoutEnum.Type.TCW_WANLIOTHERPAYMENT.value;
			Long relativeId = wanliOtherPaymentItemId;
			String transferRequestId = RandomUtil.getGUID();
			String orderNo = null;
			BigDecimal transferFromAmountValue = tcwWanliOtherPaymentItem.getAmount().multiply(new BigDecimal(100));
			String currencyCode = tcwWanliOtherPayment.getCurrencyCodeOut();
			String paymentMethodType = "BANK_ACCOUNT_DETAIL";
			String paymentMethodId = resultJOConsult
					.getJSONObject("transferToDetail")
					.getJSONObject("transferToMethod")
					.getString("paymentMethodId");
			String paymentMethodMetaData = paymentMethodMetaDataJO.toJSONString();
			BigDecimal transferToAmountValue = tcwWanliOtherPaymentItem.getAmount();
			String transferQuote = transferQuoteJO.toJSONString();
			String transferNotifyUrl = MyConfig.getUrlDomain() + AppConstant.PATH_NOTIFY_WF;
			String transferRemark = null;
			String transferMemo = null;
			String extendInfo = null;
			String purposeCode = "GDS";
			String arrivalType = null;
			String businessSceneCode = "THIRD_PARTY_PAYOUT";
			BigDecimal feeAmount = transferToDetailJO.getJSONObject("feeAmount").getBigDecimal("value");
			String resultCode = null;
			String resultMessage = null;
			String resultStatus = null;
			Integer state = TcwWanliPayoutEnum.State.INIT.value;
			tcwWanliPayout = TcwWanliPayout.tcwWanliPayout(mid, type, relativeId, transferRequestId, orderNo,
					transferFromAmountValue, currencyCode, paymentMethodType, paymentMethodId, paymentMethodMetaData,
					transferToAmountValue, transferQuote, transferNotifyUrl, transferRemark, transferMemo,
					extendInfo, purposeCode, arrivalType, businessSceneCode, feeAmount,
					resultCode, resultMessage, resultStatus, state, 1);
			tcwWanliPayoutMapper.insert(tcwWanliPayout);
		}
		
		{
	        String content = "";
	        JSONObject jsonObject = new JSONObject();
	        jsonObject.put("transferRequestId", tcwWanliPayout.getTransferRequestId());

	        JSONObject transferFromDetail = new JSONObject();
	        JSONObject transferFromAmount = new JSONObject();
	        transferFromAmount.put("currency", tcwWanliOtherPayment.getCurrencyCodeOut());
	        transferFromAmount.put("value", tcwWanliOtherPaymentItem.getAmount().multiply(new BigDecimal(100)));
	        transferFromDetail.put("transferFromAmount", transferFromAmount);
	        jsonObject.put("transferFromDetail", transferFromDetail);

	        JSONObject transferToDetail = new JSONObject();
	        JSONObject transferToMethod = new JSONObject();

	        transferToMethod.put("paymentMethodType", "BANK_ACCOUNT_DETAIL");

	        transferToMethod.put("paymentMethodMetaData", paymentMethodMetaDataJO);

	        transferToDetail.put("transferToMethod", transferToMethod);

	        JSONObject transferToAmount = new JSONObject();
	        transferToAmount.put("currency", tcwWanliOtherPayment.getCurrencyCodeOut());

	        transferToDetail.put("transferToAmount", transferToAmount);

	        transferToDetail.put("purposeCode", "GDS"); // 转账目的代码
	        //用于接收转账通知的地址，万里汇会使用此地址将转账结果通过notifyTransfer接口发送给集成商。
	        transferToDetail.put("transferNotifyUrl", MyConfig.getUrlDomain() + "/api/outer/wfStore/test4");

            transferToDetail.put("transferQuote", transferQuoteJO);

	        jsonObject.put("transferToDetail",transferToDetail);
	        
	        /*
	         * 转账业务类型码
	         * THIRD_PARTY_PAYOUT：转账到第三方卡。第三方卡包括企业卡和个人卡
	         * SAME_NAME_PAYOUT：提现到同名卡。
	         */
	        jsonObject.put("businessSceneCode", "THIRD_PARTY_PAYOUT");

	        content = JSONObject.toJSONString(jsonObject);

	        String httpMethod = "POST";
	        String clientId = tbStaticConfig.getName();
	        String uriWithQueryString = "/amsin/api/v1/business/fund/createPayout";
	        String connectedCustomerId = "";
	        /*
	         * {"businessSceneCode":"THIRD_PARTY_PAYOUT","result":{"resultCode":"PROCESSING","resultMessage":"request is processing.","resultStatus":"S"},"transferFromDetail":{"transferFromAmount":{"currency":"EUR","value":5000},"transferFromMethod":{"customerId":"2120220018087007","paymentMethodType":"BALANCE"}},"transferId":"2024061819121000110000001073757","transferOrderAddition":{},"transferRequestId":"ecc18279-3c51-4bb4-8b9d-526a203433a9","transferToDetail":{"feeAmount":{"currency":"EUR","value":15},"purposeCode":"GDS","transferNotifyUrl":"http://localhost:9999/api/outer/wfStore/test6","transferQuote":{"quoteCurrencyPair":"EUR/CNY","quoteExpiryTime":"2024-06-18T08:39:32Z","quoteId":"20230929C50030530001336311","quotePrice":"7.70174920","quoteStartTime":"2023-09-29T07:42:55Z"},"transferToAmount":{"currency":"CNY","value":38393},"transferToMethod":{"paymentMethodId":"2024061819027700120305109984749","paymentMethodType":"BANK_ACCOUNT_DETAIL"}}}
	         */
	        String result = WanliUtils.result(content, httpMethod, uriWithQueryString, clientId,connectedCustomerId);
	        System.out.println("createPayoutresult=" + result);
		}
	}

	/**
	 * 万里汇提款单支付
	 * @return
	 * @throws Exception
	 */
	@Override
	public R tkAdd(Long wanliDrawingItemId) throws Exception {

		//查询万里汇提款详情
		TcwWanliDrawingItem tcwWanliDrawingItem = new TcwWanliDrawingItem().setId(wanliDrawingItemId).queryFirst();
		//查询万里汇提款信息
		TcwWanliDrawing tcwWanliDrawing = new TcwWanliDrawing().setBid(tcwWanliDrawingItem.getPbid()).queryFirst();
		//查询公司银行信息
		TbCompanyBankInfo tbCompanyBankInfo = new TbCompanyBankInfo().setId(tcwWanliDrawingItem.getCompanyBankInfoId()).queryFirst();

		// 万里汇clientId配置
		TbStaticConfig tbStaticConfig = new TbStaticConfig().setKeyTwo("wanli-mid-clientId").queryFirst();

		//汇出金额
		BigDecimal transferFromAmountValue = BigDecimal.ZERO;
		//汇入金额
		BigDecimal transferToAmountValue = BigDecimal.ZERO;
		if (tcwWanliDrawing.getDrawingType() == TcwWanliCnyPaymentEnum.DrawingType.DRAWINGS.value){
			if (tcwWanliDrawingItem.getOutCurrencyCode().equals(TcwExchangeRateEnum.ExchangeRate.JPY.value)){
				transferFromAmountValue = tcwWanliDrawingItem.getOutSum();
			}else {
				transferFromAmountValue = tcwWanliDrawingItem.getOutSum().multiply(new BigDecimal(100));
			}
		}else {
			if (tcwWanliDrawingItem.getInCurrencyCode().equals(TcwExchangeRateEnum.ExchangeRate.JPY.value)){
				transferToAmountValue = tcwWanliDrawingItem.getInSum();
			}else {
				transferToAmountValue = tcwWanliDrawingItem.getInSum().multiply(new BigDecimal(100));
			}
		}

		// 汇出币种
		String transferFromAmountCurrency = tcwWanliDrawingItem.getOutCurrencyCode();

		//支付方式类型
		String paymentMethodType = TcwPaymentMethodTypeEnum.PaymentMethodType.BANK_ACCOUNT_DETAIL.value;

		//收款人信息
		JSONObject paymentMethodMetaData = new JSONObject();
		// 银行账户名称，如：莫程集团控股有限公司
		paymentMethodMetaData.put("bankAccountLocalName", tbCompanyBankInfo.getVyhzhmc());
		// 开户行名称，如：中国工商银行福州金山支行
		paymentMethodMetaData.put("bankLocalName", tbCompanyBankInfo.getVkhh());
		// 银行账号，如：1402267709600003989
		paymentMethodMetaData.put("bankAccountNo", tbCompanyBankInfo.getVyhzh());

		// 受益人类型：THIRD_PARTY_PERSONAL_BANK_ACCOUNT和THIRD_PARTY_COMPANY_BANK_ACCOUNT
		paymentMethodMetaData.put("beneficiaryType", "THIRD_PARTY_COMPANY_BANK_ACCOUNT");
		paymentMethodMetaData.put("bankCountryCode", "CN"); // 受益人国家编码，固定两字符
		//beneficiaryType=THIRD_PARTY_COMPANY_BANK_ACCOUNT(企业银行卡) 该routingNumber（银行支行联行号）字段必填
		paymentMethodMetaData.put("routingNumber", tbCompanyBankInfo.getVlhh()); // 联行号，如：301394000013

		//转账业务类型码。当 transferToDetail.transferToAmount.currency = CNY 时，此字段为必传。
		String businessSceneCode = TcwBusinessSceneCodeEnum.BusinessSceneCode.THIRD_PARTY_PAYOUT.value;

		JSONObject resultJOConsult = null;
		JSONObject jsonObject = new JSONObject();
		{
			String content = "";
			JSONObject transferFromDetail = new JSONObject();
			JSONObject transferFromAmount = new JSONObject();
			transferFromAmount.put("currency", transferFromAmountCurrency);
			//0 提款  1到款
			if (tcwWanliDrawing.getDrawingType() == TcwWanliCnyPaymentEnum.DrawingType.DRAWINGS.value){//提款
				transferFromAmount.put("value",transferFromAmountValue);
				tcwWanliDrawingItem.setInSum(transferFromAmountValue);//汇入金额
			}
			transferFromDetail.put("transferFromAmount",transferFromAmount);
			jsonObject.put("transferFromDetail",transferFromDetail);

			JSONObject transferToDetail = new JSONObject();
			JSONObject transferToMethod = new JSONObject();

			//默认提款单为银行卡支付
			transferToMethod.put("paymentMethodType", paymentMethodType);

			// 需要注意每个国家的简称提前设置
			transferToMethod.put("paymentMethodMetaData", paymentMethodMetaData);

			transferToDetail.put("transferToMethod", transferToMethod);

			JSONObject transferToAmount = new JSONObject();
			transferToAmount.put("currency", "CNY");
			//0 提款  1到款
			if (tcwWanliDrawing.getDrawingType() == TcwWanliCnyPaymentEnum.DrawingType.ARRIVAL.value){//到款
				transferToAmount.put("value",transferToAmountValue);
				tcwWanliDrawingItem.setOutSum(transferFromAmountValue);//汇出金额
			}

			transferToDetail.put("transferToAmount", transferToAmount);
			jsonObject.put("transferToDetail", transferToDetail);
			jsonObject.put("businessSceneCode", businessSceneCode);
			content = JSONObject.toJSONString(jsonObject);

			String httpMethod = "POST";
			String clientId = tbStaticConfig.getName();
			String uriWithQueryString = WfSubUserEnum.Type.CONSULTPAYOUT.value;
			String connectedCustomerId = "";
//			String result = WanliUtils.result(content, httpMethod, uriWithQueryString, clientId,connectedCustomerId);
//			System.out.println("consultPayoutresult=" + result);
//
//			resultJOConsult = JSON.parseObject(result);
//			boolean flag = false;
//			if (resultJOConsult.containsKey("result")) {
//				JSONObject resultJO = resultJOConsult.getJSONObject("result");
//				if (resultJO.containsKey("resultCode") && resultJO.getString("resultCode").equals("SUCCESS")) {
//					flag = true;
//				}
//			}
//			if (flag == false) {
//				return null;
//			}
		}

//		/*
//		 * 获取汇率
//		 */
//		JSONObject transferToDetailJO = JSONObject.parseObject(resultJOConsult.get("transferToDetail").toString());
		JSONObject transferQuoteJO = new JSONObject();
//		if (transferToDetailJO.containsKey("transferQuote")){
//			JSONObject transferQuoteJo = transferToDetailJO.getJSONObject("transferQuote");
//			transferQuoteJO.put("quoteId", transferQuoteJo.get("quoteId"));
//			tcwWanliDrawingItem.setExchangeRate(new BigDecimal(transferQuoteJo.get("quotePrice").toString()).setScale(6, RoundingMode.HALF_UP));//保留2位小数);//汇率
//		}
//
//		/*
//		 * 获取汇出、汇入金额
//		 */
//		//0 提款  1到款
//		JSONObject transferFromDetail = JSONObject.parseObject(resultJOConsult.get("transferFromDetail").toString());
//		BigDecimal outSum = BigDecimal.ZERO;
//		BigDecimal inSum = BigDecimal.ZERO;
//		if (tcwWanliDrawing.getDrawingType() == TcwWanliCnyPaymentEnum.DrawingType.DRAWINGS.value){//提款
//			if (transferFromDetail.containsKey("transferToAmount")){
//				JSONObject transferToAmount = transferFromDetail.getJSONObject("transferToAmount");
//				inSum = new BigDecimal(transferToAmount.get("value").toString()).setScale(2, RoundingMode.HALF_UP);
//			}
//			tcwWanliDrawingItem.setInSum(inSum);//汇入金额
//		}
//		if (tcwWanliDrawing.getDrawingType() == TcwWanliCnyPaymentEnum.DrawingType.ARRIVAL.value){//到款
//			if (transferFromDetail.containsKey("transferFromAmount")){
//				JSONObject transferFromAmount = transferFromDetail.getJSONObject("transferFromAmount");
//				outSum = new BigDecimal(transferFromAmount.get("value").toString()).setScale(2, RoundingMode.HALF_UP);
//			}
//			tcwWanliDrawingItem.setOutSum(outSum);//汇出金额
//		}
//
//
//		//手续费
//		tcwWanliDrawingItem.setProceduresSum(transferToDetailJO.getJSONObject("feeAmount").getBigDecimal("value"));
//		//手续费比例   手续费（汇出币种）= 汇出金额*手续费比例
//		BigDecimal proceduresRatio = BigDecimal.ZERO;
//		if(tcwWanliDrawingItem.getOutSum().compareTo(BigDecimal.ZERO)!=0){
//			proceduresRatio = tcwWanliDrawingItem.getProceduresSum()
//					.divide(tcwWanliDrawingItem.getOutSum(),6,BigDecimal.ROUND_HALF_UP);//保留6位小数，四舍五入
//		}
//		tcwWanliDrawingItem.setProceduresRatio(proceduresRatio);
//
		String resultMessage = null;
		Integer state = TcwWanliPayoutEnum.State.INIT.value;
//
//		//修改子表信息
//		tcwWanliDrawingItemMapper.update(tcwWanliDrawingItem);

		// 添加万里汇订单记录
		TcwWanliPayout tcwWanliPayout = null;
		{
			String mid = null;
			Integer type = TcwWanliPayoutEnum.Type.TCW_WANLIDRAWING.value;
			Long relativeId = wanliDrawingItemId;
			String transferRequestId = RandomUtil.getGUID();
			String orderNo = null;
			String currencyCode = "";
			if (tcwWanliDrawing.getDrawingType() == TcwWanliCnyPaymentEnum.DrawingType.DRAWINGS.value){
				currencyCode = transferFromAmountCurrency;
			}else {
				currencyCode = "CNY";
			}
			String paymentMethodId = resultJOConsult.getJSONObject("transferToDetail").getJSONObject("transferToMethod").getString("paymentMethodId");
			String transferQuote = transferQuoteJO.toJSONString();
			String transferNotifyUrl = MyConfig.getUrlDomain() + "/api/outer/wfStore/test4";
			String transferRemark = null;
			String transferMemo = null;
			String extendInfo = null;
			String purposeCode = "GDS";
			String arrivalType = null;
			BigDecimal feeAmount = new BigDecimal("0.44");
			String resultCode = null;

			String resultStatus = null;
			tcwWanliPayout = TcwWanliPayout.tcwWanliPayout(mid, type, relativeId, transferRequestId, orderNo,
					transferFromAmountValue, currencyCode, paymentMethodType, paymentMethodId, paymentMethodMetaData.toJSONString(),
					transferToAmountValue, transferQuote, transferNotifyUrl, transferRemark, transferMemo,
					extendInfo, purposeCode, arrivalType, businessSceneCode, feeAmount,
					resultCode, resultMessage, resultStatus, state, 1);
			tcwWanliPayoutMapper.insert(tcwWanliPayout);
		}

		if(state.equals(TcwWanliPayoutEnum.State.INIT.value)){
			JSONObject transferToDetail = JSONObject.parseObject(jsonObject.get("transferToDetail").toString());
			jsonObject.put("transferRequestId", tcwWanliPayout.getTransferRequestId());
			transferToDetail.put("purposeCode", "GDS"); // 转账目的代码
			//用于接收转账通知的地址，万里汇会使用此地址将转账结果通过notifyTransfer接口发送给集成商。
			transferToDetail.put("transferNotifyUrl", MyConfig.getUrlDomain() + "/api/outer/wfStore/test4");

			transferToDetail.put("transferQuote", transferQuoteJO);

			jsonObject.put("transferToDetail",transferToDetail);

			String content = JSONObject.toJSONString(jsonObject);

			String httpMethod = "POST";
			String clientId = tbStaticConfig.getName();
			String uriWithQueryString = "/amsin/api/v1/business/fund/createPayout";
			String connectedCustomerId = "";

			String result = WanliUtils.result(content, httpMethod, uriWithQueryString, clientId,connectedCustomerId);
			System.out.println("createPayoutresult=" + result);
		}

		return null;
	}

	@Override
	@Transactional
	public void changeToSuccess(String transferRequestId) throws Exception {
		if (transferRequestId == null || transferRequestId.length() == 0) {
			return;
		}
		
		TcwWanliPayout tcwWanliPayout = new TcwWanliPayout().setTransferRequestId(transferRequestId).queryFirst();
		if (tcwWanliPayout == null) {
			return;
		} else if (tcwWanliPayout.getState() == TcwWanliPayoutEnum.State.SUCCESS.value) {
			return;
		}
		
		tcwWanliPayout.setState(TcwWanliPayoutEnum.State.SUCCESS.value);
		tcwWanliPayoutMapper.update(tcwWanliPayout);
		
		if (tcwWanliPayout.getType() == TcwWanliPayoutEnum.Type.TCW_WANLICNYPAYMENT.value) {
			Long id = tcwWanliPayout.getRelativeId();
			tcwWanliCnyPaymentService.paySuccess(id);
		}else if (tcwWanliPayout.getType() == TcwWanliPayoutEnum.Type.TCW_WANLIDRAWING.value) {//万里汇提款单
			Long id = tcwWanliPayout.getRelativeId();
			tcwWanliDrawingService.paySuccess(id);
			//tcwWanliCnyPaymentService.paySuccess(id);
		}else if (tcwWanliPayout.getType() == TcwWanliPayoutEnum.Type.TCW_WANLIPAYMENTRETURN.value) {//万里汇预付款退回单
			Long id = tcwWanliPayout.getRelativeId();
			tcwWanliPaymentReturnService.paySuccess(id);
		}
		
	}

	/**
	 * 万里汇预付款退回支付
	 * @param wanliPaymentReturnItemId
	 * @throws Exception
	 */
	@Override
	public void addPaymentReturnItem(Long wanliPaymentReturnItemId) throws Exception {

		TcwWanliPaymentReturnItem tcwWanliPaymentReturnItem = new TcwWanliPaymentReturnItem().setId(wanliPaymentReturnItemId).queryFirst();
		if (tcwWanliPaymentReturnItem.getStatePay() == PaymentEnum.StatePay.SUCCESS.value) {
			return;
		}
		tcwWanliPaymentReturnItem.setStatePay(PaymentEnum.StatePay.PROCESS.value);

		//查询主表信息
		TcwWanliPaymentReturn tcwWanliPaymentReturn =  new TcwWanliPaymentReturn().setBid(tcwWanliPaymentReturnItem.getWanliPaymentReturnBid()).queryFirst();

		//查询退回信息
		TcwPaymentReturnItem tcwPaymentReturnItem = new TcwPaymentReturnItem().setId(tcwWanliPaymentReturnItem.getPaymentReturnItemId()).queryFirst();

		//运营公司银行信息
		ThrOperateCompanyBankInfo thrOperateCompanyBankInfo  = new ThrOperateCompanyBankInfo().setId(tcwPaymentReturnItem.getCompanyBankId()).queryFirst();

		// 万里汇clientId配置
		TbStaticConfig tbStaticConfig = new TbStaticConfig().setKeyTwo("wanli-mid-clientId").queryFirst();

		JSONObject resultJOConsult = null;
		JSONObject paymentMethodMetaData ;
		JSONObject jsonObject;
		{
			String content = "";
			jsonObject = new JSONObject();

			JSONObject transferFromDetail = new JSONObject();
			JSONObject transferFromAmount = new JSONObject();
			transferFromAmount.put("currency", tcwWanliPaymentReturn.getCurrencyCode()); // 支付币种
			transferFromDetail.put("transferFromAmount",transferFromAmount);
			jsonObject.put("transferFromDetail",transferFromDetail);

			JSONObject transferToDetail = new JSONObject();
			JSONObject transferToMethod = new JSONObject();

			transferToMethod.put("paymentMethodType","BANK_ACCOUNT_DETAIL");

			paymentMethodMetaData = new JSONObject();

			paymentMethodMetaData.put("bankAccountLocalName", thrOperateCompanyBankInfo.getVyhzhmc()); // 银行账户名称，如：莫程集团控股有限公司
			paymentMethodMetaData.put("bankLocalName", thrOperateCompanyBankInfo.getVkhh()); // 开户行名称，如：中国工商银行福州金山支行
			paymentMethodMetaData.put("bankAccountNo", thrOperateCompanyBankInfo.getVyhzh()); // 银行账号，如：1402267709600003989

			paymentMethodMetaData.put("beneficiaryType", "THIRD_PARTY_COMPANY_BANK_ACCOUNT"); // 受益人类型：THIRD_PARTY_PERSONAL_BANK_ACCOUNT和THIRD_PARTY_COMPANY_BANK_ACCOUNT
			paymentMethodMetaData.put("bankCountryCode", "CN"); // 受益人国家编码，固定两字符
			//beneficiaryType=THIRD_PARTY_COMPANY_BANK_ACCOUNT(企业银行卡) 该routingNumber（银行支行联行号）字段必填
			paymentMethodMetaData.put("routingNumber", thrOperateCompanyBankInfo.getVlhh()); // 联行号，如：301394000013

			transferToMethod.put("paymentMethodMetaData", paymentMethodMetaData);

			transferToDetail.put("transferToMethod", transferToMethod);

			JSONObject transferToAmount = new JSONObject();
			transferToAmount.put("currency", tcwWanliPaymentReturnItem.getThCurrencyCode());
			BigDecimal transferFromAmountValue = BigDecimal.ZERO;
			if (tcwWanliPaymentReturnItem.getThCurrencyCode().equals(TcwExchangeRateEnum.ExchangeRate.JPY.value)){
				transferFromAmountValue = tcwWanliPaymentReturnItem.getThAmount();
			}else {
				transferFromAmountValue = tcwWanliPaymentReturnItem.getThAmount().multiply(new BigDecimal(100));
			}
			transferToAmount.put("value", transferFromAmountValue);

			transferToDetail.put("transferToAmount", transferToAmount);
			jsonObject.put("transferToDetail", transferToDetail);
			jsonObject.put("businessSceneCode", "THIRD_PARTY_PAYOUT");
			content = JSONObject.toJSONString(jsonObject);

			String httpMethod = "POST";
			String clientId = tbStaticConfig.getName();
			String uriWithQueryString = WfSubUserEnum.Type.CONSULTPAYOUT.value;
			String connectedCustomerId = "";
			String result = WanliUtils.result(content, httpMethod, uriWithQueryString, clientId,connectedCustomerId);
			System.out.println("consultPayoutresult=" + result);

			resultJOConsult = JSON.parseObject(result);
			boolean flag = false;
			if (resultJOConsult.containsKey("result")) {
				JSONObject resultJO = resultJOConsult.getJSONObject("result");
				if (resultJO.containsKey("resultCode") && resultJO.getString("resultCode").equals("SUCCESS")) {
					flag = true;
				}
			}
			if (flag == false) {
				return;
			}
		}
		/*
		 * 获取汇率
		 */
		JSONObject transferToDetailJO = JSONObject.parseObject(resultJOConsult.get("transferToDetail").toString());
		JSONObject transferQuoteJO = new JSONObject();
		if (transferToDetailJO.containsKey("transferQuote")){
			JSONObject transferQuoteJo = transferToDetailJO.getJSONObject("transferQuote");
			transferQuoteJO.put("quoteId", transferQuoteJo.get("quoteId"));
			tcwWanliPaymentReturnItem.setExchangeRate(new BigDecimal(transferQuoteJo.get("quotePrice").toString()));
		}
		//手续费
		if (transferToDetailJO.containsKey("feeAmount")){
			JSONObject feeAmount = transferToDetailJO.getJSONObject("feeAmount");
			tcwWanliPaymentReturnItem.setServiceCharge(new BigDecimal(feeAmount.get("value").toString()));
		}

		/*
		 * 获取支付金额
		 */
		JSONObject transferFromDetailJo = JSONObject.parseObject(resultJOConsult.get("transferFromDetail").toString());
		if (transferFromDetailJo.containsKey("transferFromAmount")){
			JSONObject transferFromAmount = transferFromDetailJo.getJSONObject("transferFromAmount");
			tcwWanliPaymentReturnItem.setZfAmount(new BigDecimal(transferFromAmount.get("value").toString()).divide(new BigDecimal(100),2,BigDecimal.ROUND_HALF_UP));
		}

		// 添加万里汇订单记录
		TcwWanliPayout tcwWanliPayout = null;
		{
			String mid = null;
			Integer type = TcwWanliPayoutEnum.Type.TCW_WANLIPAYMENTRETURN.value;
			Long relativeId = wanliPaymentReturnItemId;
			String transferRequestId = RandomUtil.getGUID();
			String orderNo = null;
			BigDecimal transferFromAmountValue = tcwWanliPaymentReturnItem.getZfAmount();
			String currencyCode = tcwWanliPaymentReturnItem.getThCurrencyCode();
			String paymentMethodType = "BANK_ACCOUNT_DETAIL";
			String paymentMethodId = resultJOConsult
					.getJSONObject("transferToDetail")
					.getJSONObject("transferToMethod")
					.getString("paymentMethodId");
			BigDecimal transferToAmountValue = tcwWanliPaymentReturnItem.getThAmount();
			String transferQuote = transferQuoteJO.toJSONString();
			String transferNotifyUrl = MyConfig.getUrlDomain() + "/api/outer/wfStore/test4";
			String transferRemark = null;
			String transferMemo = null;
			String extendInfo = null;
			String purposeCode = "GDS";
			String arrivalType = null;
			String businessSceneCode = "THIRD_PARTY_PAYOUT";
			BigDecimal feeAmount = transferToDetailJO.getJSONObject("feeAmount").getBigDecimal("value");
			String resultCode = null;
			String resultMessage = null;
			String resultStatus = null;
			Integer state = TcwWanliPayoutEnum.State.INIT.value;
			tcwWanliPayout = TcwWanliPayout.tcwWanliPayout(mid, type, relativeId, transferRequestId, orderNo,
					transferFromAmountValue, currencyCode, paymentMethodType, paymentMethodId, paymentMethodMetaData.toJSONString(),
					transferToAmountValue, transferQuote, transferNotifyUrl, transferRemark, transferMemo,
					extendInfo, purposeCode, arrivalType, businessSceneCode, feeAmount,
					resultCode, resultMessage, resultStatus, state, 1);
			tcwWanliPayoutMapper.insert(tcwWanliPayout);
		}

		tcwWanliPaymentReturnItemMapper.update(tcwWanliPaymentReturnItem);

		{

			JSONObject transferToDetail = JSONObject.parseObject(jsonObject.get("transferToDetail").toString());
			jsonObject.put("transferRequestId", tcwWanliPayout.getTransferRequestId());
			transferToDetail.put("purposeCode", "GDS"); // 转账目的代码
			//用于接收转账通知的地址，万里汇会使用此地址将转账结果通过notifyTransfer接口发送给集成商。
			transferToDetail.put("transferNotifyUrl", MyConfig.getUrlDomain() + "/api/outer/wfStore/test4");

			transferToDetail.put("transferQuote", transferQuoteJO);

			jsonObject.put("transferToDetail", transferToDetail);

			String content = JSONObject.toJSONString(jsonObject);

			String httpMethod = "POST";
			String clientId = tbStaticConfig.getName();
			String uriWithQueryString = WfSubUserEnum.Type.CREATEPAYOUT.value;
			String connectedCustomerId = "";

			String result = WanliUtils.result(content, httpMethod, uriWithQueryString, clientId, connectedCustomerId);
			System.out.println("createPayoutresult=" + result);
			resultJOConsult = JSON.parseObject(result);
			boolean flag = false;
			if (resultJOConsult.containsKey("result")) {
				JSONObject resultJO = resultJOConsult.getJSONObject("result");
				if (resultJO.containsKey("resultCode") && resultJO.getString("resultStatus").equals("S")) {
					flag = true;
				}else {
					//失败参数
					tcwWanliPayout.setResultStatus(resultJO.get("resultStatus").toString());
					tcwWanliPayout.setResultMessage(resultJO.get("resultMessage").toString());
					tcwWanliPayout.setResultCode(resultJO.get("resultCode").toString());
					tcwWanliPayoutMapper.update(tcwWanliPayout);

					//修改详情支付状态
					tcwWanliPaymentReturnItem.setStatePay(PaymentEnum.StatePay.FAILED.value);
					tcwWanliPaymentReturnItemMapper.update(tcwWanliPaymentReturnItem);
				}
			}
			if (flag == false) {
				return;
			}
		}
	}
}
